import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreConnectionPNames;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ChoviWu on 2018/05/06
 * Description:
 */
@Slf4j
public class ScoreTest implements PageProcessor {


//    public static final String URL = "http://112.124.54.19/Score/score.html";

    public static final String URL = "http://112.124.54.19/Score/score.html";

    public static final String IMAGE = "http://112.124.54.19/Score/score/getVerCode.action?identity=3C96A9941A2614F4784B906E1501DF06&schoolIdentity=2EE917122A021BF6308BA220CC3C495A&st="+new Date().getTime();

    protected Site site = Site.me().setRetryTimes(3).setSleepTime(3000).setTimeOut(30000)  //默认重试三次  睡眠10s  超时30s
            .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36");



    @Test
    public void test(){
        Map map = new HashMap();
        map.put("schoolIdentity","2EE917122A021BF6308BA220CC3C495A");
        map.put("s_Id","0");
        map.put("b_y","2017");
        map.put("t_m","2");
        map.put("s_n","1443041003");
        map.put("p_d","wuchaowei");
        map.put("c_k","");
//        map.put("v_c",parseCode(IMAGE));
        map.put("v_c","1111");
        map.put("identity","3C96A9941A2614F4784B906E1501DF06");
        String json = HttpUtil.sendHttpPost(URL,map);
        log.info(json);
    }

    @Override
    public void process(Page page) {
    }

    @Override
    public Site getSite() {
        return site;
    }

    private String parseCode(String url ){
            return ImgDoOCR.parse(url);
    }

    @Test
    public void test2(){
        parseCode(IMAGE);
    }

}
